import req from '@/utils/request'
import * as url from '../constants/api'
/**
 * @returns {{message: string, data: object}}
 * @description 获取新闻频道
 */
export function getUserChannels() {
    return req({
        url: url.CHANNELS,
        method: 'GET',
    })
}
/**
 * @returns {{message: string, data: object}}
 * @description 获取所有新闻频道
 */
export function getAllChannels() {
    return req({
        url: url.ALLCHANNELS,
        method: 'GET',
    })
}

/**
 * @param {{channel_id: number, timestamp: number}}
 * @returns {{message: string, data: object}}
 * @description 获取新闻频道
 */
export function getArticles(params) {
    return req({
        url: url.ARTICLES,
        method: 'GET',
        params
    })
}

/**
 * @param  {string} keyword
 * @returns {Promise<{ message: string, data: object}> }
 * @description 搜索
 */
export function getSearch(keyword) {
    return req({
        url: url.SEARCH,
        method: 'GET',
        params: {
            q: keyword
        }
    })
}

/**
 * @param  {string} keyword
 * @returns {Promise<{ message: string, data: object}> }
 * @description 搜索建议列表
 */
export function suggestion(keyword) {
    return req({
        url: url.SUGGESTION,
        method: 'GET',
        params: {
            q: keyword
        }
    })
}

/**
 * 
 * @param {{number}} article_id
 */
export function getUserNews(article_id) {
    return req({
        url: url.NEWS + article_id,
        method: 'GET',
    })
}

export function follow(userId) {
    return req({
        url: url.FOLLOW,
        method: 'POST',
        data: {
            target: userId
        }
    })
}
export function noFollow(userId) {
    return req({
        url: url.NOFOLLOW + userId,
        method: 'DELETE',
    })
}
// 收藏
export function collect(target) {
    return req({
        url: url.COLLECTION,
        method: 'POST',
        data: {
            target
        }
    })
}
export function noCollect(target) {
    return req({
        url: url.NOCOLLECTION + target,
        method: 'DELETE',
    })
}

// 点赞
export function like(target) {
    return req({
        url: url.LIKE,
        method: 'POST',
        data: {
            target
        }
    })
}
export function noLike(target) {
    return req({
        url: url.NOLIKE + target,
        method: 'DELETE',
    })
}